<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>我的</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="/node_modules/LobsterUIFrame/weui/css/weui.css" />
    <link rel="stylesheet" href="/node_modules/LobsterUIFrame/weui/css/weuix.css" />
    <script src="/node_modules/LobsterUIFrame/weui/js/zepto.min.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/zepto.weui.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/swipe.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/macy.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/php.js"></script>
    <script src="/lobstersdk/lobster.js"></script>
    <script src="/jslib/template-web.js"></script>
    <style>
        .weui-grid__icon {
            position: relative;
        }

        .weui-panel::before {
            border-top: none;
        }

        .weui-panel::after {
            border-bottom: none;
        }

        .weui-grids:before {
            border-top: none;
        }

        .weui-grids::after {
            border-left: none;
        }
    </style>
</head>

<body ontouchstart>
    <div class="page-bd-15">
        <div class="weui-panel">
            <div class="weui-panel__bd" id="loginkuai2">
                <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg" id="btnuser">
                    <div class="weui-media-box__hd">
                        <div class="weui-avatar">
                            <img id="imgUrl" src="/node_modules/LobsterUIFrame/weui/favicon.png" /><span
                                class="weui-icon-success weui-icon-safe-warn"></span>
                        </div>
                    </div>
                    <div class="weui-media-box__bd">
                        <h4 id="nickName" class="weui-media-box__title">未登录</h4>
                        <p id="userName" class="weui-media-box__desc"></p>
                    </div>
                </a>
            </div>
        </div>
        <div class="weui-cells" id="bloggerinfo" style="display: none;">
            <div class="weui-cell weui-cell_access" id="toblogger">
                <div class="weui-cell__bd">
                    <p>博主首页</p>
                </div>
                <div class="weui-cell__ft"></div>
            </div>
            <div class="weui-cell weui-cell_access" id="tofans">
                <div class="weui-cell__bd">
                    <p>我的粉丝</p>
                </div>
                <div class="weui-cell__ft"></div>
            </div>
            <div class="weui-cell weui-cell_access" id="toconcerns">
                <div class="weui-cell__bd">
                    <p>我的关注</p>
                </div>
                <div class="weui-cell__ft"></div>
            </div>
        </div>
        <div class="weui-btn-area" id="divtongbu">
            <a href="javascript:;" class="weui-btn weui-btn_primary" id="btntongbu">同步信息</a>
        </div>
        <div class="weui-btn-area" id="divexit">
            <a href="javascript:;" class="weui-btn weui-btn_warn" id="btnexit">退出登录</a>
        </div>
    </div>

    <div id='tb' class="weui-tab" style="height:auto;">
        <div class="weui-tabbar tab-bottom">
            <a href="index.html" class="weui-tabbar__item">
                <i class="icon icon-27 f27 weui-tabbar__icon"></i>
                <p class="weui-tabbar__label ">社区</p>
            </a>
            <a href="search.html" class="weui-tabbar__item ">
                <i class="icon icon-4 f27 weui-tabbar__icon"></i>
                <p class="weui-tabbar__label">搜索</p>
            </a>
            <a href="mine.html" class="weui-tabbar__item ">
                <i class="icon icon-30 f27 weui-tabbar__icon"></i>
                <p class="weui-tabbar__label f-green">我的</p>
            </a>
        </div>
    </div>
</body>

</html>


<script>

    lobsterh5.main({
        data: {
            blogger: {},
            user: {},
        },
        //初始化页面
        pageload: function () {
            this.initevent();
            this.getUserInfo();

        },
        getUserInfo: function () {
            var self = this;
            lobsterh5.GetMPUserInfo(user => {
                self.data.user = user;
                $("#imgUrl").attr("src", user.ImgUrl);
                $("#nickName").text(user.Nickname);
                $("#userName").text("账号:" + user.UserName);
            });
        },
        //初始化事件
        initevent: function () {
            var self = this;

            //显示退出登录按钮
            if (lobsterh5.hasLogin()) {
                self.getBlogger();
                $("#divexit").show();
            } else {
                $("#divexit").hide();
            }
            //退出登录
            $("#btnexit").click(function () {
                if (lobsterh5.hasLogin()) {
                    $.confirm("确定要退出当前帐号吗？", function () {
                        var workId = lobsterh5.GetWorkId()
                        lobsterh5.ExitLogin();
                        location.href = 'index.html?WorkId=' + workId;
                    }, function () {
                        //点击取消后的回调函数
                    })
                }
            });
            $("#btnuser").click(function () {
                if (lobsterh5.hasLogin()) {
                    location.href = "/lobstersdk/edituser.html";
                } else {
                    location.href = "/lobstersdk/login.html?callback=" + encodeURI("/weuiapp/3223/index.html?WorkId=" + lobsterh5.GetWorkId());
                }
            });
            $("#btntongbu").click(function () {
                self.saveBlogger();
            })
            $("#toblogger").click(function () {
                location.href = "blogger/index.html?bloggerId=" + self.data.blogger.BloggerId;
            })
            $("#tofans").click(function () {
                location.href = "blogger/fans.html?bloggerId=" + self.data.blogger.BloggerId + "&bloggerUserId=" + self.data.blogger.UserId + "&nickName=" + self.data.blogger.NickName;
            })
            $("#toconcerns").click(function () {
                location.href = "blogger/concerns.html?bloggerId=" + self.data.blogger.BloggerId + "&bloggerUserId=" + self.data.blogger.UserId + "&nickName=" + self.data.blogger.NickName;
            })
        },
        getBlogger() {
            var self = this;
            lobsterh5.GET("/lowcode/APP20211203093514696/name/?fun=Dynamic.GetBlogger", {
                userId: localStorage.getItem("userId")
            }).then(res => {
                self.data.blogger = res.blogger;
                if (res.blogger.BloggerId > 0) {
                    $("#btntongbu").text("同步信息");
                    $("#bloggerinfo").show();
                } else {
                    $("#btntongbu").text("开通博主");
                    $("#bloggerinfo").hide();
                }
            }).catch(res => {
                console.log(res.msg || res);
                $.toast(res.msg || res, 'forbidden');
            })
        },
        saveBlogger() {
            var self = this;
            lobsterh5.POST("/lowcode/APP20211203093514696/name/?fun=Dynamic.SaveBlogger", {
                NickName: self.data.user.Nickname,
                UserImg: self.data.user.ImgUrl,
                UserId: self.data.user.MPUserId,
            }).then(res => {
                $.toast("操作成功", 'text');
                self.getBlogger();
            }).catch(res => {
                console.log(res.msg || res);
                $.toast(res.msg || res, 'forbidden');
            })
        }
    }, false)
</script>